package view.UIlayer
{
	import com.greensock.*;
	import com.greensock.easing.*;
	
	import control.CardMachine;
	import control.GameRule;
	
	import event.CustomEvent;
	
	import flash.display.MovieClip;
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.geom.Point;
	import flash.text.TextField;
	
	import view.UIlayer.ButtonViewLayer;
	import view.UIlayer.CardView;
	import view.UIlayer.CardViewLayer;
	import view.UIlayer.ScoreboardView;
	
	import vo.CardVo;
	import vo.GameCardsVO;
	import vo.GameMode;
	
	public class CardViewLayer extends Sprite
	{
		private var cardViewList:Array = new Array();
		private var gameModel:GameMode = GameMode.getInstance();
		
		public function CardViewLayer()
		{
			super();
		}
		
		// 展示卡牌
		public function displayCard( ):void{
			clearCardView();
			displayCardPC();
			displayCardMy();
		}	
		
		// 展示卡牌
		public function displayCardPC(  ):void{
			gameModel.playMe("assets/sound/sound_2_(flip).mp3");
			
			var timeline:TimelineLite = new TimelineLite();
			var targetX:int;
			var targetY:int;
			var tmpX:int = 0;
			var tmpY:int = 120;
			
			
			for(var i : int = 0; i < gameModel.gameCardsVO.pcCardList.length; i++){				
				var tmpCardView:CardView = new CardView( gameModel.gameCardsVO.pcCardList[i] );
				
				tmpCardView.y = 0;
				tmpCardView.x = stage.width;
				targetX = i * 20 + 150 + tmpX;
				targetY = tmpY;
				addChild(tmpCardView);
				cardViewList.push( tmpCardView );
				TweenLite.to( tmpCardView, 1, {x:targetX, y:targetY, ease:Elastic.easeOut});
			}	
			
			
		}	
		
		// 展示卡牌
		public function displayCardMy(  ):void{
			gameModel.playMe("assets/sound/sound_2_(flip).mp3");
			
			var timeline:TimelineLite = new TimelineLite();
			var targetX:int;
			var targetY:int;
			var tmpX:int = -20;
			var tmpY:int = 270;
			
			
			
			for(var i : int = 0; i < gameModel.gameCardsVO.myCardList.length; i++){				
				var tmpCardView:CardView = new CardView( gameModel.gameCardsVO.myCardList[i] );
				
				tmpCardView.y = 0;
				tmpCardView.x = stage.width;
				targetX = i * 20 + 150 + tmpX;
				targetY = tmpY;
				addChild(tmpCardView);
				cardViewList.push( tmpCardView );
				TweenLite.to( tmpCardView, 1, {x:targetX, y:targetY, ease:Elastic.easeOut});
			}	
			
			
		}	
		
		//暴力移除，从新开始
		public function clearCardView( ) : void {			
			while(numChildren > 0) {this.removeChildAt(0);}			
			
		}	
	}
}